﻿using Abp.Authorization.Users;
using Abp.Extensions;
using NetCore.CustomAttributes;
using NetCore.Enums;
using NetCore.ValueObjects;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace NetCore.Authorization.Users
{
    public class User : AbpUser<User>
    {
        //系统登录默认密码
        public const string DefaultPassword = "123qwe";//admin/123qwe

        public static string CreateRandomPassword()
        {
            return Guid.NewGuid().ToString("N").Truncate(16);
        }

        public static User CreateTenantAdminUser(int tenantId, string emailAddress)
        {
            var user = new User
            {
                TenantId = tenantId,
                UserName = AdminUserName,
                Name = AdminUserName,
                Surname = AdminUserName,
                EmailAddress = emailAddress,
                IdCardNo = "500108199003071177",
                Mobile = "18840927050",
                Address = new Address(),
                Roles = new List<UserRole>()
            };

            user.SetNormalizedNames();

            return user;
        }

        #region 扩展字段



        #region 一对多关系表 第一次生成migration时不能配置

        //public User()
        //{
        //    OrganizationUsers = new HashSet<OrganizationUser>();
        //    ProjectUsers = new HashSet<ProjectUser>();
        //}

        ///// <summary>
        ///// 机构 多个机构
        ///// </summary>
        //[NotSet, Description("机构")]
        //public virtual HashSet<OrganizationUser> OrganizationUsers { get; set; }
        ///// <summary>
        ///// 项目 参与多个项目
        ///// </summary>
        //[NotSet, Description("项目")]
        //public virtual HashSet<ProjectUser> ProjectUsers { get; set; }


        #endregion

        ///// <summary>
        ///// 邮件
        ///// </summary>
        //[Description("邮件"), Required, StringLength(MaxEmailAddressLength), Regex(Regxes.Email)]
        //public override string EmailAddress { get; set; }

        /// <summary>
        /// 手机
        /// </summary>
        [Description("手机"), Required, Regex(Regxes.MobilePhone)]
        public string Mobile { get; set; }

        /// <summary>
        /// 身份证号码
        /// </summary>
        [Required, Regex(Regxes.IdCardNo)]
        public string IdCardNo { get; set; }
        /// <summary>
        /// 用户状态(注意可空枚举类型的反射)
        /// </summary>
        [Description("用户状态")]//, Column("State")
        public UserStatus? Status { get; set; }
        /// <summary>
        /// 用户类型
        /// </summary>
        [Description("用户类型")]
        public UserType? UserType { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        [Description("性别")]
        public Sex? Sex { get; set; }
        /// <summary>
        /// 最近登陆时间
        /// </summary>
        [Description("最近登陆时间")]
        public DateTime? LastLoginTime { get; set; }
        /// <summary>
        /// 生日
        /// </summary>
        [Description("生日")]
        public DateTime? BirthDay { get; set; }

        /// <summary>
        /// 个性签名
        /// </summary>
        [MaxLength(MaxUserNameLength)]
        public string Motto { get; set; }

        /// <summary>
        /// 头像图片Key
        /// </summary>
        public string HeadPortraitKey { get; set; }

        /// <summary>
        /// 个人签章照片-Base64
        /// </summary>
        public string SignatureBase64 { get; set; }
        /// <summary>
        /// 个人签章水印照片-WatermarkBase64
        /// </summary>
        public string WatermarkBase64 { get; set; }
        /// <summary>
        /// 是否完成新手引导
        /// </summary>
        public bool IsCompleteGuide { get; set; }
        /// <summary>
        /// 是否完成实名认证
        /// </summary>
        public bool IsRealName { get; set; }
        /// <summary>
        /// 签章的SignAccountId值
        /// </summary>
        public string SignAccountId { get; set; }

        /// <summary>
        /// 所属地区
        /// </summary>
        [Description("所属地区")]
        public Address Address { get; set; }
        /// <summary>
        /// 等级/可改为枚举
        /// </summary>
        [Description("等级")]
        public TreeNodeLevel Level { get; set; }

        #endregion
    }
}
